package com.mocha.bss.websocket;


import com.coffee.ws.command.CoffeeCommandEnum;
import com.coffee.ws.metadata.CoffeeMessageType;
import com.mocha.bss.websocket.message.DocDownloadPushMessage;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: songkui
 * @since: 2023/2/24 9:14
 */
public enum HandlerMapCmdType implements CoffeeCommandEnum {

    PushDownload(4000, DocDownloadPushMessage.class),
    ;

    public int cmd;
    private boolean verifyType;
    private CoffeeMessageType messageType;
    private final Class request;

    HandlerMapCmdType(int cmd, boolean verifyType, CoffeeMessageType messageType, Class request) {
        this.cmd = cmd;
        this.verifyType = verifyType;
        this.request = request;
        this.messageType = messageType;
    }

    HandlerMapCmdType(int cmd, CoffeeMessageType messageType, Class request) {
        this.cmd = cmd;
        this.verifyType = true;
        this.request = request;
        this.messageType = messageType;
    }


    HandlerMapCmdType(int cmd, Class request) {
        this.cmd = cmd;
        this.request = request;
        this.verifyType = true;
        this.messageType = CoffeeMessageType.Text;
    }

    @Override
    public int cmd() {
        return this.cmd;
    }

    @Override
    public String cmdName() {
        return this.name();
    }

    @Override
    public Class request() {
        return this.request;
    }


    @Override
    public boolean verifyType() {
        return this.verifyType;
    }

    @Override
    public CoffeeMessageType messageType() {
        return this.messageType;
    }


    //转换成 map
    private static Map<Integer, CoffeeCommandEnum> handlerTypeMap = Arrays.stream(HandlerMapCmdType.values())
            .collect(Collectors.toMap(HandlerMapCmdType::cmd, rtype -> rtype));

    public static HandlerMapCmdType valueOfCode(int cmd) {
        return (HandlerMapCmdType) handlerTypeMap.get(cmd);
    }

    public static Map<Integer, CoffeeCommandEnum> getMap() {
        return handlerTypeMap;
    }


}
